using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Peradigm.Framework.Domain.Security;
using Peradigm.Framework.UI.Web;

using Liberty.Domain.NoteManagement;

public delegate void NoteAdded( Note note );


namespace Liberty.UI.NoteManagement.Controls
{
    public partial class NewNoteView : AbstractLibertyControl
    {
        #region Constants
        #endregion

        #region Event Handlers
        protected void cmdAdd_Click( object sender, EventArgs e )
        {
            string noteText = this.NoteText;
            // TO-DO: Add client side validation or a custom validation control to disable
            // Add button when text is not entered
            if( noteText.Trim() != String.Empty )
            {
                Note newNote = new Note( this.ApplicationUser, this.NoteText );
                this.RaiseNoteAddedEventUsing( newNote );
                this.NoteText = String.Empty;
            }
        }
        #endregion

        #region Events
        public event NoteAdded NoteAddedListeners
        {
            add
            {
                i_NoteAddedEvent += value;
            }
            remove
            {
                i_NoteAddedEvent -= value;
            }
        }
        #endregion

        #region Methods
        #endregion

        #region Properties
        #endregion

        #region Private Methods
        private void RaiseNoteAddedEventUsing( Note newNote )
        {
            if( this.NoteAddedEvent != null )
            {
                this.NoteAddedEvent( newNote );
            }
        }
        #endregion

        #region Private Properties
        private User ApplicationUser
        {
            get
            {
                UserVariable userVariable = new UserVariable();
                return userVariable.User;
            }
        }

        private NoteAdded NoteAddedEvent
        {
            get
            {
                return i_NoteAddedEvent;
            }
        }

        private string NoteText
        {
            get
            {
                return txtNote.Text;
            }
            set
            {
                txtNote.Text = value;
            }
        }
        #endregion

        #region Construction and Finalization
        #endregion

        #region Data Elements
        private NoteAdded i_NoteAddedEvent;
        #endregion
    }
}